fn main() {
    println!("Hello, world!");
    let i = foo();
    let s = foo_str();
    // let _s = foo_str_ref();
    println!("i got {} when call foo. {}", i, s);
}

fn foo() -> u32 {
    let i = 100u32;
    i // copy
}

fn foo_str() -> String {
    let s = "abc".to_string();
    s // move
}

// 不能工作
// fn foo_str_ref() -> &String {
//     let s = "abc".to_string();
//     &s
// }

// option and result
#[cfg(test)]
mod tests {
    #[test]
    fn option_result() {
        let s = String::from("");
        let a: Option<String> = Some(s);
        assert_eq!(a.is_none(), false);
    }

    fn ret_result() -> Result<(), String> {
        return Result::Ok(());
    }

    #[test]
    fn result_test() {
        let r = ret_result();
        assert_eq!(r.expect("none"), ());

        assert_eq!(Some("car").unwrap_or("bike"), "car");
        assert_eq!(None.unwrap_or("bike"), "bike");


        let p = std::env::var("OS_NAME");
        assert_eq!(p.unwrap_or_default(), "");
    }
}